﻿using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using Pay.DTO.card;

namespace Pay.Service.AutoMapper {

    public class CartMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public CartMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<Cart, cart_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
                .ForMember(dest => dest.product_id, src => src.MapFrom(c => c.ProductId))
                .ForMember(dest => dest.product, src => src.MapFrom(c => c.Product))
                .ForMember(dest => dest.User, src => src.MapFrom(c => c.User))
                .ForMember(dest => dest.sku_id, src => src.MapFrom(c => c.SkuId))
                .ForMember(dest => dest.product_sku, src => src.MapFrom(c => c.ProductSku))
                 .ForMember(dest => dest.shop_id, src => src.MapFrom(c => c.ShopId))
                   .ForMember(dest => dest.merchant_no, src => src.MapFrom(c => c.MerchantNo))
                  .ForMember(dest => dest.shop, src => src.MapFrom(c => c.ShopInfo))
                .ForMember(dest => dest.quantity, src => src.MapFrom(c => c.Quantity));
            _cfg.CreateMap<cart_dto, Cart>()
               .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
               .ForMember(dest => dest.SkuId, src => src.MapFrom(c => c.sku_id))
               .ForMember(dest => dest.ProductSku, src => src.MapFrom(c => c.product_sku))
               .ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
               .ForMember(dest => dest.Product, src => src.MapFrom(c => c.product))
               .ForMember(dest => dest.ProductId, src => src.MapFrom(c => c.product_id))
               .ForMember(dest => dest.Quantity, src => src.MapFrom(c => c.quantity))
                 .ForMember(dest => dest.ShopId, src => src.MapFrom(c => c.shop_id))
                   .ForMember(dest => dest.MerchantNo, src => src.MapFrom(c => c.merchant_no))
                   .ForMember(dest => dest.Quantity, src => src.MapFrom(c => c.quantity))
               .ForMember(dest => dest.User, src => src.MapFrom(c => c.User));
            _cfg.CreateMap<cart_dto, cart_ex>();
        }
    }
}
